﻿/*** MikeWare Framework ************************************
* This class is part of product of MikeWare.Framework.
* 
* Author      : Mike Cheers
* Mail        : mikecheers@126.com
* Create Date : 2018/9/18
* Summary     : 
* 
* 
* Modified By : 
* Date        : 
* Mail        : 
* Comment     : 
**************************************************************/

namespace MikeWare.Components.MikeForm
{
    using System;
    using System.Reflection;
    using System.Windows.Forms;

    public static class DoubleBufferedHelper
    {
        /// <summary>
        /// 为Form双缓冲，解决闪烁问题
        /// </summary>
        /// <param name="form"></param>
        /// <param name="flag"></param>
        public static void DoubleBuffered(this Form form, bool flag)
        {
            Type type = form.GetType();
            PropertyInfo property = type.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
            property.SetValue(form, flag, null);
        }
        /// <summary>
        /// 为WinForm Control双缓冲，解决闪烁问题
        /// </summary>
        /// <param name="control"></param>
        /// <param name="flag"></param>
        public static void DoubleBuffered(this Control control, bool flag)
        {
            Type type = control.GetType();
            PropertyInfo property = type.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
            property.SetValue(control, flag, null);
        }
    }
}
